﻿using Md.Api.Entity.DapperModels.MdDB;
using Md.Api.Model.Manage.MdProduct.Request;
using Md.Dapper.Repositories.Md;

namespace Md.Api.Service.Manage.MdProduct;
/// <summary>
/// 添加产品服务
/// </summary>
public class InsertMdProductService : ApiBase<RequestInsertMdProductModel>
{
    /// <summary>
    /// 产品仓储
    /// </summary>
    public MdProductRep mdProductRep { get; set; }
    /// <summary>
    /// 执行
    /// </summary>
    protected override void ExecuteMethod()
    {
        var model = new MdProductModel();

        model.Title = Parameter.Title;
        model.Description = Parameter.Description;
        model.Quantity = Parameter.Quantity;
        model.MarketPrice = Parameter.MarketPrice;
        model.SeliingPrice = Parameter.SeliingPrice;
        model.PurchaseLink = Parameter.PurchaseLink;
        model.Content = Parameter.Content;
        model.Illustrate = Parameter.Illustrate;
        model.Picture = Parameter.Picture;
        model.ThumPicture = Parameter.ThumPicture;
        model.Category = Parameter.Category;
        model.Status = Parameter.Status;
        model.DelFlag = "0";
        model.CreateBy = userKey?.ToString();
        model.CreateTime = DateTime.Now;
        model.Remark = Parameter.Remark;

        var res = mdProductRep.Insert(model);

        if (Convert.ToInt64(res) > 0)
        {
            Result.Data = mdProductRep.GetMdProductById(Convert.ToInt64(res));
        }
        else
        {
            Result.Data = res;
        }
    }
}

